/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * Licensed under Simplified BSD License
 *
 *
 * @author: jin Chen 
 * @date: Nov 29, 2005$
 * @version: 1.0
 */
package edu.psu.geovista.app.gmatrix.toolkit;

import edu.psu.geovista.app.gmatrix.canvas.DfMatrixCanvas;

import java.awt.*;

public class DfHighlightSupport {

      //this is for highlight show info
     String[] rownames;
     String[] colnames;

     Point loc=new Point();//highlight location
     Point index=new Point();//row,col index of highlighted cell

    DfMatrixCanvas canvas;
    
     public void hightlight(Point index){
         index.setLocation(index);
     }

    public DfHighlightSupport() {
    }

    public DfHighlightSupport(DfMatrixCanvas canvas) {
        this.canvas = canvas;
    }

    /**
     *
     * @param g
     * @param loc  screen location of highlight tooltip
     */
     public void draw(Graphics g, Point loc){
         String[] msg = this.getHighlightMsg(index.x, index.y);
         Rectangle bd=new Rectangle(loc.x,loc.y,60,60);
         draw(g,bd,msg);

     }
     private void draw(Graphics g, Rectangle bd, String[] highlightTexts){


                 int x = bd.x;
                 int y = bd.y;
                 g.setColor(Color.orange );
                 g.fillRect(x,y,3,3);//to show location
                 g.setColor(new Color(255,255,255,100));
                 g.fillRect(x,y,80,50);
                 String[] texts = highlightTexts;
                 int tx=x+5;
                 int ty=y+15;
                 int textHt=20;
                 if(texts!=null){
                     for (int i=0;i<texts.length ;i++){
                         g.setFont(new Font("ARIAL",Font.BOLD ,16));
                         g.setColor(Color.black );
                         String text = texts[i];
                         if(text!=null)
                            g.drawString(text,tx,ty);
                         ty=ty+textHt;
                     }
                 }

    }
    protected String[] getHighlightMsg(int row, int col ){
        String[] msg=new String[2];
        String[] rownames = this.getRownames();
        String[] colnames = this.getColnames();

       

        if(rownames !=null&&rownames.length >row){
           msg[0]=rownames[row];

        }
        else{
            msg[0]="row:"+row;
        }

        if(colnames !=null){
                  msg[1]=colnames[col];

               }
               else{
                   msg[1]="column:"+col;
               }
        return msg;

    }
     public String[] getColnames() {
        return colnames;
    }

    public void setColnames(String[] colnames) {
        this.colnames = colnames;
    }

    public String[] getRownames() {
        return rownames;
    }

    public void setRownames(String[] rownames) {
        this.rownames = rownames;
    }

    public Point getIndex() {
        return index;
    }

    public void setIndex(Point index) {
        this.index.setLocation(index);
    }

    public DfMatrixCanvas getCanvas() {
        return canvas;
    }

    public void setCanvas(DfMatrixCanvas canvas) {
        this.canvas = canvas;
    }
}
